<%@ page language="java" pageEncoding="UTF-8"%><%@ page import="org.jiucai.cas.data.*"%><%

//是否显示验证码
Integer showVeryCode = 0;

Integer passwordErrorMaxCount = 0;
Object sessPwdErrorMaxCount = session.getAttribute(Constant.AUTH_SESS_PWD_ERR_MAX_COUNT);
if(null != sessPwdErrorMaxCount){
	passwordErrorMaxCount = ( Integer ) sessPwdErrorMaxCount;
}

Integer passwordErrorCount = 0;
Object sessPwdErrorCount = session.getAttribute(Constant.AUTH_SESS_PWD_ERR_COUNT);
if(null != sessPwdErrorCount){
	passwordErrorCount = ( Integer )  sessPwdErrorCount;
}

if( passwordErrorCount > passwordErrorMaxCount) {
	showVeryCode =1;
}

%>
<%@ include file="/cas/common.jsp"%>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/rookie/Rookie.js?${pageContext.request.contextPath}/js/rookie/rookie.swf"></script>
<script type="text/javascript">
<!--//--><![CDATA[<!--
	
	$(function() {
		

		$("#userName").focus();
		
		var errMsg = '${failed_msg}';
		
		var resetLoginBtn = function (){
			$('#login').removeAttr("disabled");
		};
		
		if('' != errMsg){
			resetLoginBtn();
		}
		
		Rookie(function(){
			var userName = this.read("_app_login_name");
			
			if(userName){
				$("#userName").val(userName);
			}
		});
		
		//noraml support for both ff,ie8
		$("form").submit(function(e){
			$('#alert_message').html('&nbsp;&nbsp;登录中...');
			
			$('#login').attr({"disabled":"disabled"});
			

			if($("#userName").val() == ''){
				$('#alert_message').html('请输入帐号');
				resetLoginBtn();
				$("#userName").focus();
				return false;
			}
			
			if($("#password").val() == ''){
				$('#alert_message').html('请输入密码');
				resetLoginBtn();
				$("#password").focus();
				return false;
			}
			
			<% if( showVeryCode > 0 ) { %>
				if($("#veryCode").val() == ''){
					$('#alert_message').html('请输入验证码');
					resetLoginBtn();
					$("#veryCode").focus();
					return false;
				}
			
			<% } %>
			
			Rookie(function(){
				
				
				var userName = $("#userName").val();
				if(userName){
					this.write("_app_login_name",userName);
				}
				
			});
		});
		
		
		<% if( showVeryCode > 0 ) { %>

		
		$('#codeSpan').css({
			'display' : 'none'
		});
		
		$('#refreshCode').css({
			'cursor' : 'pointer'
		});

		$('#veryCode').bind('focus',function() {
			$('#codeSpan').css({
				'display' : 'inline-block'
			});

		});
		$('#refreshCode').bind('click',function() {
			$('#codeSpan').css({
				'display' : 'inline-block'
			});
			var url = '${pageContext.request.contextPath}/cas/img.jsp?r=' + Math.random();
			$('#imgCode').get(0).src= url;

		});
		
		<% } %>
		
	});


//--><!]]>
</script>
</head>

<body>

    <!-- Le styles -->

    <style type="text/css">
      body {
        padding-top: 40px;
        padding-bottom: 40px;
        background-color: #f5f5f5;
      }

      .form-signin {
        max-width: 320px;
        padding: 19px 29px 29px;
        margin: 0 auto 20px;
        background-color: #eee;
        border: 1px solid #e5e5e5;
        -webkit-border-radius: 5px;
           -moz-border-radius: 5px;
                border-radius: 5px;
        -webkit-box-shadow: 0 1px 2px rgba(0,0,0,.05);
           -moz-box-shadow: 0 1px 2px rgba(0,0,0,.05);
                box-shadow: 0 1px 2px rgba(0,0,0,.05);
      }
      .form-signin .form-signin-heading,
      .form-signin .checkbox {
        margin-bottom: 10px;
      }

	  #alert_message{ 
	  	color: #ee0000; 
	  	padding-left: 10px;
	  }
    </style>



    <div class="container">

      <form class="form-signin" id="loginForm" name="loginForm" action="${pageContext.request.contextPath}/auth/login" method="post">
        <h2 class="form-signin-heading">登录Demo系统</h2>
        
   <div class="control-group">
    <div class="controls">

        <div class="input-prepend">
  			<span class="add-on">帐号</span>
 			<input type="text" class="input-large" placeholder="请输入帐号" id="userName" name="userName" value="${userName }"  maxlength="200"  />
		</div>

        
    </div>
   </div>
  
  
   <div class="control-group">
    <div class="controls">
         
         
        <div class="input-prepend">
  			<span class="add-on">密码</span>
  			<input type="password" class="input-large" placeholder="请输入密码" name="password" id="password"  maxlength="200" />
		</div>
		
    </div>
   </div>
        
        
        <%  if(showVeryCode > 0) { %>
        
   <div class="control-group">
    <div class="controls">
  			<input class="input-small" id="veryCode" name="veryCode" maxlength="7" placeholder="请输入验证码"/> 

  			<span id="codeSpan">
			<img id="imgCode" style="vertical-align: middle;" src="${pageContext.request.contextPath}/cas/img.jsp" alt="验证码" title="验证码"/>
			<span id="refreshCode" class="help-inline" title="刷新验证码">看不清？</span>
			</span>

    </div>
  </div>
  

		<% } %>



   <div class="control-group">
    <div class="controls">
    
    	<button id="login" class="btn btn-primary" type="submit">登录</button>
    	
    	<span id="alert_message">${failed_msg}</span>

    </div>
  </div>

		
      </form>

    </div> <!-- /container -->
    
    

    

    <!-- Le javascript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    
    <%@ include file="/common/widget/bootstrap.jsp"%>

  </body>
</html>
